

define(['jquery','backbone','views/todo', 'models/todo','collections/todo'],
    function($,Backbone, TodoView, TodoModel, TodoCollection){

    var AppView = Backbone.View.extend({

        el:$('#placeholder'),

        initialize:function(){
            this.todos = new TodoCollection();
            this.todos.bind('all', this.render, this);
            this.todos.fetch();
        },

        render:function(){
            console.log('Data fetched');
            var element = $(this.el);

            this.todos.each(function(model){
                var todoView = new TodoView({model:model});
                element.append(todoView.el.innerHTML);
            });
        }
    });

    return AppView;
});